import ImagePreviewMasked from '@/components/viewWidget/ImagePreviewMasked'
import React, { Component } from 'react'
import AuthImg from '../AuthImg/AuthImg'

export default class ImageWidget extends Component {

    state = {
        imagePreviewVisul: false
    }

    openPreview = () => {
        this.setState({
            imagePreviewVisul: true
        })
    }

    closePreview = () => {
        this.setState({
            imagePreviewVisul: false
        })
    }

    render() {
        const { noAuth } = this.props;
        return (
            <>
                {
                    noAuth ? (
                        <img
                            {...this.props}
                            onClick={this.openPreview}
                        />
                    ) : (
                        <AuthImg
                            {...this.props}
                            authSrc={this.props.src}
                            onClick={this.openPreview}
                        />
                    )
                }
                <ImagePreviewMasked
                    visual={this.state.imagePreviewVisul}
                    onCancel={this.closePreview}
                    src={this.props.src}
                    alt={this.props.alt}
                />
            </>
        )
    }
}
